package com.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
//sessionA.html
public class SessionAttribute extends HttpServlet {

	
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		doPost(request, response);
	}

	
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html");//  application/json"  //"image/png"
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		HttpSession session=request.getSession();
		String option=request.getParameter("option");
		String key=request.getParameter("key");
		String value=request.getParameter("value");
		if ("add".equals(option)) {
			session.setAttribute(key, value);
		}else if ("remove".equals(option)) {
			System.out.println(11111111);
			session.removeAttribute(key);
			System.out.println(session.getAttribute(key));
		}else if ("update".equals(option)) {
			session.setAttribute(key, value);
		}
	}

}
